<template>
  <div>
    <div class="mvtop">
      <span class="iconfont icon-zuoyoujiantou" @click="$router.push('/mv')"
      >MV</span>
      <span class="iconfont icon-fenxiang"></span>
    </div>
    <!-- mv播放 -->
    <div>
      <video ref="video" controls="controls" :src="mvlist.url"></video>
    </div>

    <van-tabs v-model="active">
      <!-- 简介 -->
      <van-tab title="简介">
        <div class="mvlistbox1">
          <span>MV：{{ mvlist1.name }}</span>
          <p>演唱者：{{ mvlist1.artistName }}</p>
          <p class="desc">{{ mvlist1.desc }}</p>
          <span class="iconfont icon-MV">{{ mvlist1.subCount }}</span>
          <span class="iconfont icon-shoucang" @click="getMvSubFun"></span>
          <p class="time">发布时间：{{ mvlist1.publishTime }}</p>
        </div>
        <!-- 推荐mv -->
        <div class="tjmv">
          <div class="tjspanbox">
            <span>推荐MV </span>
            <span class="iconfont icon-zuo"></span>
          </div>

          <div class="tjmvbox">
            <div class="tjbox" v-for="(item, index) in resultlist" :key="index" @click="edit(item.id)">
              <div
                class="tjimg"
                :style="'background-image: url(' + item.picUrl + ')'"
              ></div>
              <p>{{ item.name }}</p>
              <p>{{ item.artistName }}</p>
            </div>
          </div>
        </div>
      </van-tab>
      <van-tab title="评论">
        <!-- 评论 -->
        <div class="pl">
          <ul>
            <li v-for="(item, index) in pllist" :key="index">
              <div
                class="plimg"
                :style="'background-image: url(' + item.user.avatarUrl + ')'"
              ></div>
              <span class="userid"
                >{{ item.user.nickname }}
                <span
                  class="iconfont icon-dianzan"
                  @click="like(item.commentId)"
                >
                  <span class="likenum">{{ item.likedCount }}</span>
                </span>
              </span>
              <span class="pltime">{{ item.timeStr }}</span>
              <span class="pltext">{{ item.content }}</span>
            </li>
          </ul>
          <div class="intext">
            <input
              type="text"
              placeholder="请输入需要发表的评论"
              v-model="text"
            />
            <button @click="add2">发送</button>
          </div>
        </div>
      </van-tab>
    </van-tabs>
  </div>
</template>
<script>
import {
  getMvUrl,
  getMvDetail,
  getPersonaLized,
  getCommentMv,
  getComment,
  getCommentLike,
  getMvSub,
  getMvSublist,
} from "../../api/base";
import { Toast } from "vant";
export default {
  data() {
    return {
      mvlist: [],
      mvlist1: [],
      resultlist: [],
      active: 2,
      active1: 2,
      pllist: [],
      text: "",
    };
  },
  methods: {
    edit(id) {
      this.$route.query.id = id;
      this.getMvUrlFun();
      this.getMvDetailFun();
      this.getCommentMvFun();
      this.getMvSublistFun();
    },
    //mv播放地址
    getMvUrlFun() {
      getMvUrl({ id: this.$route.query.id }).then((data) => {
        // console.log(this.$route.query);
        // console.log(data.data);
        this.mvlist = data.data;
      });
    },
    //mv数据
    getMvDetailFun() {
      getMvDetail({ mvid: this.$route.query.id }).then((data) => {
        // console.log(data.data);
        this.mvlist1 = data.data;
      });
    },
    //推荐mv
    getPersonaLizedFun() {
      getPersonaLized().then((data) => {
        // console.log(data.result);
        this.resultlist = data.result;
      });
    },
    //评论
    getCommentMvFun() {
      getCommentMv({ id: this.$route.query.id }).then((data) => {
        console.log(data.comments);
        this.pllist = data.comments;
      });
    },
    //发送评论
    add2() {
      getComment({
        t: 1,
        type: 1,
        id: this.$route.query.id,
        content: this.text,
      }).then((data) => {
        console.log("已发送", data);
        // this.text.push()
      });
      this.text = "";
    },
    //点赞评论
    like(id) {
      getCommentLike({ id: this.$route.query.id, cid: id, type: 1, t: 1 }).then(
        (data) => {
          console.log("成功点赞", data);
          Toast("成功点赞");
        }
      );
    },
    //收藏
    getMvSubFun() {
      getMvSub({ mvid: this.$route.query.id, t: 1 }).then((data) => {
        console.log(data);
        Toast("收藏成功");
      });
    },
    //收藏mv
    getMvSublistFun() {
      getMvSublist().then((data) => {
        console.log(data);
      });
    },
  },
  created() {
    this.getMvUrlFun();
    this.getMvDetailFun();
    this.getCommentMvFun();
    this.getMvSublistFun();
    this.getPersonaLizedFun();
    // this.getMvSubFun();
    // this.like();
    // this.add2();
    // console.log(this.text)
  },
};
</script>

<style lang="less">
.mvtop {
  height: 50px;
  position: relative;
  background-color: #d4473c;
  .icon-fenxiang {
    font-size: 23px;
    position: absolute;
    top: 12px;
    right: 20px;
    color: white;
  }
  .icon-zuoyoujiantou {
    font-size: 18px;
    position: absolute;
    left: 12px;
    top: 12px;
    color: #fff;
  }
}
video {
  width: 100%;
}
.mvlistbox1 {
  position: relative;
  // margin-top: 20px;
  height: 150px;
  // width: 100%;
  // border: 1px solid black;
  border-bottom: 1px solid #d0d0d0;
  span {
    width: 200px;
    position: absolute;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    // display: inline-block;
    margin-top: 10px;
    margin-left: 20px;
  }
  .iconfont {
    position: absolute;
    font-size: 15px;
    color: #9a9a9a;
    margin-top: 100px;
  }
  .icon-shoucang {
    margin-left: 120px;
    //   margin-top: 0px;
    top: 3px;
  }
  p {
    margin-left: 20px;
    margin-top: 40px;
    position: absolute;
  }
  .desc {
    width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-left: 20px;
    margin-top: 70px;
    position: absolute;
  }
  .time {
    font-size: 10px;
    color: #9a9a9a;
    margin-left: 225px;
    position: absolute;
    margin-top: 102px;
  }
}
.tjmv {
  margin-top: 10px;
  // border: 1px solid black;
  .tjspanbox {
    display: flex;
    justify-content: space-between;
    // border: 1px solid black;
    margin: 0px 10px;
  }
  .tjmvbox {
    .tjbox {
      height: 100px;
      border: 1px solid #f3f3f3;
      box-shadow: 0px 2px 5px 0px #888888;
      margin: 10px 10px;
      border-radius: 10px;
      // position: relative;
      .tjimg {
        width: 90px;
        height: 90px;
        background-size: cover;
        border-radius: 10px;
        margin-top: 5px;
        margin-left: 5px;
      }
      p {
        width: 150px;
        margin-left: 110px;
        margin-top: -75px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 20px;
      }
      p:last-child {
        margin-left: 110px;
        margin-top: 0px;
        font-size: 15px;
        color: #a79aa7;
      }
    }
  }
}
.pl {
  ul {
    // width: 100%;
    li {
      // border: 1px solid black;
      margin: 10px 10px;
      // position: relative;
      // width: 100%;
      // height: 200px;
      border-bottom: 1px solid #eaeaea;
      .plimg {
        width: 50px;
        height: 50px;
        border: 1px solid black;
        border-radius: 50%;
        background-size: cover;
      }
      .userid {
        position: absolute;
        margin-left: 65px;
        margin-top: -45px;
        font-size: 17px;
        .iconfont {
          margin-left: 10px;
          .likenum {
            // margin-left: 0px;
            font-size: 10px;
            color: #9a9a9a;
          }
        }
      }
      .pltime {
        position: absolute;
        margin-left: 65px;
        margin-top: -20px;
        font-size: 10px;
        color: #9a9a9a;
      }
      .pltext {
        display: block;
        // width: 100%;
        margin: 15px 40px;
        font-size: 15px;
        // background-color: #f3f3f3;
      }
    }
  }
}
.intext {
  width: 100%;
  height: 40px;
  position: fixed;
  left: 0px;
  bottom: 0px;
  background-color: white;
  border-top: 1px solid #f3f3f3;
  input {
    width: 200px;
    height: 25px;
    border-radius: 20px;
    // float: right;
    margin-left: 60px;
    margin-top: 5px;
    border: 1px solid #e0e0e0;
  }
  button {
    width: 50px;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    background-color: white;
    margin-left: 10px;
  }
}
</style>
